package com.teemor.demo.base;

import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Hashtable;
import java.util.LinkedHashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.PriorityQueue;
import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentLinkedQueue;
import java.util.concurrent.SynchronousQueue;
import java.util.concurrent.locks.ReentrantLock;
import java.util.logging.Logger;

/**
 * @Description:
 * @author zhoulk
 * @date: 2020/4/21
 */
public class Test{


    public static void main(String[] args) {

        HashMap hashMap = new HashMap();
        hashMap.keySet();
        hashMap.put("1",1);



        LinkedHashMap linkedHashMap = new LinkedHashMap(1);
        linkedHashMap.put("k","v");
        linkedHashMap.remove("k");
        linkedHashMap.keySet();

        ConcurrentHashMap concurrentHashMap = new ConcurrentHashMap();
        concurrentHashMap.put(null,"v");
        concurrentHashMap.get("k");

        Collections.synchronizedMap(hashMap);

        Hashtable hashtable = new Hashtable();
        hashtable.put(null,1);
        hashtable.get(1);
        hashtable.elements();

        LinkedList linkedList = new LinkedList();
        linkedList.add("A");

        SynchronousQueue synchronousQueue = new SynchronousQueue();


        HashSet set = new HashSet();
        set.add(1);

        set.iterator();

        ArrayList<Integer> arrayList = new ArrayList<>();
        arrayList.add(1);

        PriorityQueue priorityQueue = new PriorityQueue();

        ConcurrentLinkedQueue concurrentLinkedQueue = new ConcurrentLinkedQueue();

        BlockingQueue blockingQueue = new ArrayBlockingQueue(16);



    }
        int [] array = new int[16]; //默认数组
        int nextIndex = 0;//下一个可插入位置
        public void addNode(int e) {
            int index = nextIndex;
            int parentIndex = index /2;
            while (index > 0 && array[parentIndex] > e) {
                array[index] = array[parentIndex];
                index = parentIndex;
                parentIndex = index /2;
            }
            array[index] = e;
            nextIndex ++;
        }

        public void downAdjust(int[] array, int parentIndex, int nextIndex) {
            int lastIndex = nextIndex - 1;
            int tempNode = array[parentIndex];
            int left = 2*parentIndex +1 ;
            int right = 2*parentIndex +2;
            while (left > lastIndex) {
                int children = left;
                //当存在右节点时，找出左右节点中较小的节点
                if (right<=lastIndex) {
                    children = array[left] < array[right] ? left : right;
                }
                //如果子节点大于当前节点，则直接退出循环
                if (array[children] > tempNode) {
                   break;
                }
                //使用子节点值覆盖当前节点
                array[parentIndex] = array[children];
                parentIndex = children;
                left = 2*parentIndex +1 ;
                right = 2*parentIndex +2;
            }
            array[parentIndex] = tempNode;
        }

        public void buildHeap() {
            for (int i = (nextIndex - 2) /2;i>=0;i--) {
                downAdjust(array, i, nextIndex);
            }
        }


}



